<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <base href="${BaseContext}">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
    <meta charset="utf-8">
    <meta name="renderer" content="webkit">
    <link rel="stylesheet" href="static/css/base.css">
    <link rel="stylesheet" href="static/css/forget_password.css">
	<link rel="stylesheet" href="static/css/css.css">
   	
	<script src="static/js/jquery-3.2.1.min.js"></script>
   	

</head>

<body>
    <main>
        <div class="container">
            <form class="ma" id="emailForm" action="checkVerify.do" method="post">
                <div class="form_header">
                    <div class="form_title">
                        <h2>忘记密码</h2>
                		<input type="text" placeholder="请输入用户编号" onblur="chechAccount();" name="loginId" id="tId">
                    </div>
                    <div class="form_back">
                        <a href="login.do">返回</a>
                    </div>
                </div>
                		<input type="hidden" id="userEmail" value="">
                <div class="form_body">
                    	<input type="email" placeholder="请输入绑定邮箱" name="email" id="email">
                    	<input type="text" placeholder="请输入验证码" name="verify">
                    	<input type="button" value="发邮件获取验证码" onclick="submitEmail();">
                    
                    <input type="submit" value="提交">
                </div>
                <div class="form_footer">
                    <div class="FAQ">
                        <span>收不到邮件？查看</span><a href="javascript:;">常见问题</a>
                    </div>
                </div>
            </form>
        </div>
        
    </main>
    <script type="text/javascript">
    function chechAccount(){
		var tId = $('#tId').val();
		$.post('checkAccount.do',{loginId:tId},function(data){
			$('#userEmail').val(data.email);
		},'json');
  	}
	  
		function submitEmail(){
			//alert('发送验证码!');
			var tId = $('#tId').val();
			var email = $('#email').val();
			var userEmail = $('#userEmail').val();
			//改为ajax提交邮箱
			if(tId==null && tId==''){
				alert('请输入用户编号！');
			}else if(email==null && email==''){
				//先验证邮箱合法性
				alert('邮箱验证失败，请输入正确的邮箱格式！');
			}else if(email!=userEmail){
				alert('邮箱验证失败，请输入正确的绑定邮箱！');
			}else{
				$.post('email.do',{email:email,loginId:tId},function(data){
					console.log(data);
					alert('验证码已发送到邮箱，请注意查收!');
				},'json');
			}
		}
    </script>
</body>

</html>